import {
    queryandcreatethesender,
    querythelistofmassmessagers,
    gethistorymessagedetailapi,
    sendmessageapi,
    getmsessageresidueapi
} from '../../api/message'
import user from "../../../utils/user"
import { dateFormat, confirm } from "../../../utils/util"
const app = getApp(); //获取应用实例

Page({

    /**
     * 页面的初始数据
     */
    data: {
        showorderpop: false,
        sendafter: 0,
        showpop: false,
        sendNumber: 0,
        id: 0,
        selectAll: false,
        beginPayTime: "",
        endPayTime: "",
        beginLoginTime: "",
        endLoginTime: "",
        beginRegisterTime: "",
        endRegisterTime: "",
        serveCompanyIds: [],
        serveCompanyIdsname: [],
        beginPayTimeReverse: "",
        endPayTimeReverse: "",
        beginLoginTimeReverse: "",
        endLoginTimeReverse: "",
        beginRegisterTimeReverse: "",
        endRegisterTimeReverse: "",
        serveCompanyIdsReverse: [],
        serveCompanyIdsReversename: [],
        showtotle: false,
        type: "",
        isshowpopup: false,
        showpicker: '1',
        start: dateFormat('YYYY/mm/dd',new Date()),
        end: dateFormat('YYYY/mm/dd',new Date()),
        starttime: [0, 0, 0],
        endtime: [0, 0, 0],
        currentyear: new Date().getFullYear(),
        yearsarr: [],
        mounthsarr: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
        daysarr: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30'],
        daysarr28: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28'],
        daysarr29: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29'],
        daysarr30: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30'],
        daysarr31: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31']
    },

    /**
     * 生命周期函数--监听页面加载
     */
    async onLoad(options) {
        this.setData({
            id: options.id
        })
    },
    /**
     * 生命周期函数--监听页面显示
     */
    async onShow() {
        await user.waitLogin()
        let resfirst = await gethistorymessagedetailapi(this.data.id)
        let ressecond = await getmsessageresidueapi()
        this.setData({
            sendNumber: resfirst.data.sendNumber,
            sendafter: ressecond.data.smsBalance - resfirst.data.sendNumber,
            showtotle: resfirst.data.sendNumber == 0 ? false : true,
        })
        let year = this.data.currentyear
        let oldyear = year - 29
        let oldyeararr = []
        let newyeararr = []
        for (let index = 0; index < 29; index++) {
            oldyeararr.push(oldyear + index)
        }
        newyeararr.push(year)
        for (let index = 1; index <= 10; index++) {
            newyeararr.push(year + index)
        }
        let resoult = oldyeararr.concat(newyeararr)
        resoult.forEach((ele, index) => {
            resoult[index] = ele
        })
        this.setData({
            yearsarr: resoult
        })
    },
    changepicker(e) {
        console.log(e.currentTarget.dataset.i);
        this.setData({
            showpicker: e.currentTarget.dataset.i
        })
    },
    showpopup(event) {
        this.setData({
            start: dateFormat('YYYY/mm/dd',new Date()),
            end: dateFormat('YYYY/mm/dd',new Date()),
            daysarr: this.data.daysarr31
        })
        let y = new Date().getFullYear()
        let m = new Date().getMonth() + 1
        let d = new Date().getDate()
        console.log(y, m, d);
        let sy = this.data.yearsarr.findIndex((ele, index) => {
            return ele == y
        })
        let sm = this.data.mounthsarr.findIndex((ele, index) => {
            return ele == m
        })
        let sd = this.data.daysarr.findIndex((ele, index) => {
            return ele == d
        })
        let ey = this.data.yearsarr.findIndex((ele, index) => {
            return ele == y
        })
        let em = this.data.mounthsarr.findIndex((ele, index) => {
            return ele == m
        })
        let ed = this.data.daysarr.findIndex((ele, index) => {
            return ele == d
        })
        this.setData({
            starttime: [sy, sm, sd],
            endtime: [ey, em, ed]
        })
        // console.log(e.currentTarget.dataset.type);
        // if (e.currentTarget.dataset.type == 'okpaytime' && this.data.beginPayTime != '') {
        //     let startvalue = this.data.beginPayTime.split('-')
        //     let endvalue = this.data.endPayTime.split('-')
        //     startvalue = startvalue.map((ele, index) => {
        //         return ele * 1
        //     })
        //     endvalue = endvalue.map((ele, index) => {
        //         return ele * 1
        //     })
        //     let sy = this.data.yearsarr.findIndex((ele, index) => {
        //         return ele == startvalue[0]
        //     })
        //     let sm = this.data.mounthsarr.findIndex((ele, index) => {
        //         return ele == startvalue[1]
        //     })
        //     let sd = this.data.daysarr.findIndex((ele, index) => {
        //         return ele == startvalue[2]
        //     })
        //     let ey = this.data.yearsarr.findIndex((ele, index) => {
        //         return ele == endvalue[0]
        //     })
        //     let em = this.data.mounthsarr.findIndex((ele, index) => {
        //         return ele == endvalue[1]
        //     })
        //     let ed = this.data.daysarr.findIndex((ele, index) => {
        //         return ele == endvalue[2]
        //     })
        //     this.setData({
        //         start: this.data.beginPayTime,
        //         end: this.data.endPayTime,
        //         starttime: [sy, sm, sd],
        //         endtime: [ey, em, ed]
        //     })
        // }
        // if (e.currentTarget.dataset.type == 'oklogintime' && this.data.beginLoginTime != '') {
        //     let startvalue = this.data.beginLoginTime.split('-')
        //     let endvalue = this.data.endLoginTime.split('-')
        //     startvalue = startvalue.map((ele, index) => {
        //         return ele * 1
        //     })
        //     endvalue = endvalue.map((ele, index) => {
        //         return ele * 1
        //     })
        //     let sy = this.data.yearsarr.findIndex((ele, index) => {
        //         return ele == startvalue[0]
        //     })
        //     let sm = this.data.mounthsarr.findIndex((ele, index) => {
        //         return ele == startvalue[1]
        //     })
        //     let sd = this.data.daysarr.findIndex((ele, index) => {
        //         return ele == startvalue[2]
        //     })
        //     let ey = this.data.yearsarr.findIndex((ele, index) => {
        //         return ele == endvalue[0]
        //     })
        //     let em = this.data.mounthsarr.findIndex((ele, index) => {
        //         return ele == endvalue[1]
        //     })
        //     let ed = this.data.daysarr.findIndex((ele, index) => {
        //         return ele == endvalue[2]
        //     })
        //     this.setData({
        //         start: this.data.beginLoginTime,
        //         end: this.data.endLoginTime,
        //         starttime: [sy, sm, sd],
        //         endtime: [ey, em, ed]
        //     })
        // }
        // if (e.currentTarget.dataset.type == 'okregistertime' && this.data.beginRegisterTime != '') {
        //     let startvalue = this.data.beginRegisterTime.split('-')
        //     let endvalue = this.data.endRegisterTime.split('-')
        //     startvalue = startvalue.map((ele, index) => {
        //         return ele * 1
        //     })
        //     endvalue = endvalue.map((ele, index) => {
        //         return ele * 1
        //     })
        //     let sy = this.data.yearsarr.findIndex((ele, index) => {
        //         return ele == startvalue[0]
        //     })
        //     let sm = this.data.mounthsarr.findIndex((ele, index) => {
        //         return ele == startvalue[1]
        //     })
        //     let sd = this.data.daysarr.findIndex((ele, index) => {
        //         return ele == startvalue[2]
        //     })
        //     let ey = this.data.yearsarr.findIndex((ele, index) => {
        //         return ele == endvalue[0]
        //     })
        //     let em = this.data.mounthsarr.findIndex((ele, index) => {
        //         return ele == endvalue[1]
        //     })
        //     let ed = this.data.daysarr.findIndex((ele, index) => {
        //         return ele == endvalue[2]
        //     })
        //     this.setData({
        //         start: this.data.beginRegisterTime,
        //         end: this.data.endRegisterTime,
        //         starttime: [sy, sm, sd],
        //         endtime: [ey, em, ed]
        //     })
        // }
        // if (e.currentTarget.dataset.type == 'nopaytime' && this.data.beginPayTimeReverse != '') {
        //     let startvalue = this.data.beginPayTimeReverse.split('-')
        //     let endvalue = this.data.endPayTimeReverse.split('-')
        //     startvalue = startvalue.map((ele, index) => {
        //         return ele * 1
        //     })
        //     endvalue = endvalue.map((ele, index) => {
        //         return ele * 1
        //     })
        //     let sy = this.data.yearsarr.findIndex((ele, index) => {
        //         return ele == startvalue[0]
        //     })
        //     let sm = this.data.mounthsarr.findIndex((ele, index) => {
        //         return ele == startvalue[1]
        //     })
        //     let sd = this.data.daysarr.findIndex((ele, index) => {
        //         return ele == startvalue[2]
        //     })
        //     let ey = this.data.yearsarr.findIndex((ele, index) => {
        //         return ele == endvalue[0]
        //     })
        //     let em = this.data.mounthsarr.findIndex((ele, index) => {
        //         return ele == endvalue[1]
        //     })
        //     let ed = this.data.daysarr.findIndex((ele, index) => {
        //         return ele == endvalue[2]
        //     })
        //     this.setData({
        //         start: this.data.beginPayTimeReverse,
        //         end: this.data.endPayTimeReverse,
        //         starttime: [sy, sm, sd],
        //         endtime: [ey, em, ed]
        //     })
        // }
        // if (e.currentTarget.dataset.type == 'nologintime' && this.data.beginLoginTimeReverse != '') {
        //     let startvalue = this.data.beginLoginTimeReverse.split('-')
        //     let endvalue = this.data.endLoginTimeReverse.split('-')
        //     startvalue = startvalue.map((ele, index) => {
        //         return ele * 1
        //     })
        //     endvalue = endvalue.map((ele, index) => {
        //         return ele * 1
        //     })
        //     let sy = this.data.yearsarr.findIndex((ele, index) => {
        //         return ele == startvalue[0]
        //     })
        //     let sm = this.data.mounthsarr.findIndex((ele, index) => {
        //         return ele == startvalue[1]
        //     })
        //     let sd = this.data.daysarr.findIndex((ele, index) => {
        //         return ele == startvalue[2]
        //     })
        //     let ey = this.data.yearsarr.findIndex((ele, index) => {
        //         return ele == endvalue[0]
        //     })
        //     let em = this.data.mounthsarr.findIndex((ele, index) => {
        //         return ele == endvalue[1]
        //     })
        //     let ed = this.data.daysarr.findIndex((ele, index) => {
        //         return ele == endvalue[2]
        //     })
        //     this.setData({
        //         start: this.data.beginLoginTimeReverse,
        //         end: this.data.endLoginTimeReverse,
        //         starttime: [sy, sm, sd],
        //         endtime: [ey, em, ed]
        //     })
        // }
        // if (e.currentTarget.dataset.type == 'noregistertime' && this.data.beginRegisterTimeReverse != '') {
        //     let startvalue = this.data.beginRegisterTimeReverse.split('-')
        //     let endvalue = this.data.endRegisterTimeReverse.split('-')
        //     startvalue = startvalue.map((ele, index) => {
        //         return ele * 1
        //     })
        //     endvalue = endvalue.map((ele, index) => {
        //         return ele * 1
        //     })
        //     let sy = this.data.yearsarr.findIndex((ele, index) => {
        //         return ele == startvalue[0]
        //     })
        //     let sm = this.data.mounthsarr.findIndex((ele, index) => {
        //         return ele == startvalue[1]
        //     })
        //     let sd = this.data.daysarr.findIndex((ele, index) => {
        //         return ele == startvalue[2]
        //     })
        //     let ey = this.data.yearsarr.findIndex((ele, index) => {
        //         return ele == endvalue[0]
        //     })
        //     let em = this.data.mounthsarr.findIndex((ele, index) => {
        //         return ele == endvalue[1]
        //     })
        //     let ed = this.data.daysarr.findIndex((ele, index) => {
        //         return ele == endvalue[2]
        //     })
        //     this.setData({
        //         start: this.data.beginRegisterTimeReverse,
        //         end: this.data.endRegisterTimeReverse,
        //         starttime: [sy, sm, sd],
        //         endtime: [ey, em, ed]
        //     })
        // }
        this.setData({
            isshowpopup: true,
            showpicker: "1",
            type: event.currentTarget.dataset.type
        })
    },
    cancle() {
        this.setData({
            isshowpopup: false
        })
    },
    myChangestart(e) {
        console.log(e.detail.value);
        let arr = e.detail.value
        if (this.data.yearsarr[arr[0]] % 4 == 0 && this.data.yearsarr[arr[0]] % 100 != 0 || this.data.yearsarr[arr[0]] % 400 == 0) {
            if (this.data.mounthsarr[arr[1]] == 2) {
                this.setData({
                    daysarr: this.data.daysarr29
                })
            } else if (this.data.mounthsarr[arr[1]] == 4 || this.data.mounthsarr[arr[1]] == 6 || this.data.mounthsarr[arr[1]] == 9 || this.data.mounthsarr[arr[1]] == 11) {
                this.setData({
                    daysarr: this.data.daysarr30
                })
            } else if (this.data.mounthsarr[arr[1]] == 1 || this.data.mounthsarr[arr[1]] == 3 || this.data.mounthsarr[arr[1]] == 5 || this.data.mounthsarr[arr[1]] == 7 || this.data.mounthsarr[arr[1]] == 8 || this.data.mounthsarr[arr[1]] == 10 || this.data.mounthsarr[arr[1]] == 12) {
                this.setData({
                    daysarr: this.data.daysarr31
                })
            }
        } else {
            if (this.data.mounthsarr[arr[1]] == 2) {
                this.setData({
                    daysarr: this.data.daysarr28
                })
            } else if (this.data.mounthsarr[arr[1]] == 4 || this.data.mounthsarr[arr[1]] == 6 || this.data.mounthsarr[arr[1]] == 9 || this.data.mounthsarr[arr[1]] == 11) {
                this.setData({
                    daysarr: this.data.daysarr30
                })
            } else if (this.data.mounthsarr[arr[1]] == 1 || this.data.mounthsarr[arr[1]] == 3 || this.data.mounthsarr[arr[1]] == 5 || this.data.mounthsarr[arr[1]] == 7 || this.data.mounthsarr[arr[1]] == 8 || this.data.mounthsarr[arr[1]] == 10 || this.data.mounthsarr[arr[1]] == 12) {
                this.setData({
                    daysarr: this.data.daysarr31
                })
            }
        }
        this.data.starttime = e.detail.value
        this.setData({
            starttime: e.detail.value,
            start: `${this.data.yearsarr[e.detail.value[0]]}/${this.data.mounthsarr[e.detail.value[1]]>10?this.data.mounthsarr[e.detail.value[1]]:'0'+this.data.mounthsarr[e.detail.value[1]]}/${this.data.daysarr[e.detail.value[2]]>10?this.data.daysarr[e.detail.value[2]]:'0'+this.data.daysarr[e.detail.value[2]]}`
        })
        console.log(this.data.start);
    },
    myChangeend(e) {
        console.log(e.detail.value);
        let arr = e.detail.value
        if (this.data.yearsarr[arr[0]] % 4 == 0 && this.data.yearsarr[arr[0]] % 100 != 0 || this.data.yearsarr[arr[0]] % 400 == 0) {
            if (this.data.mounthsarr[arr[1]] == 2) {
                this.setData({
                    daysarr: this.data.daysarr29
                })
            } else if (this.data.mounthsarr[arr[1]] == 4 || this.data.mounthsarr[arr[1]] == 6 || this.data.mounthsarr[arr[1]] == 9 || this.data.mounthsarr[arr[1]] == 11) {
                this.setData({
                    daysarr: this.data.daysarr30
                })
            } else if (this.data.mounthsarr[arr[1]] == 1 || this.data.mounthsarr[arr[1]] == 3 || this.data.mounthsarr[arr[1]] == 5 || this.data.mounthsarr[arr[1]] == 7 || this.data.mounthsarr[arr[1]] == 8 || this.data.mounthsarr[arr[1]] == 10 || this.data.mounthsarr[arr[1]] == 12) {
                this.setData({
                    daysarr: this.data.daysarr31
                })
            }
        } else {
            if (this.data.mounthsarr[arr[1]] == 2) {
                this.setData({
                    daysarr: this.data.daysarr28
                })
            } else if (this.data.mounthsarr[arr[1]] == 4 || this.data.mounthsarr[arr[1]] == 6 || this.data.mounthsarr[arr[1]] == 9 || this.data.mounthsarr[arr[1]] == 11) {
                this.setData({
                    daysarr: this.data.daysarr30
                })
            } else if (this.data.mounthsarr[arr[1]] == 1 || this.data.mounthsarr[arr[1]] == 3 || this.data.mounthsarr[arr[1]] == 5 || this.data.mounthsarr[arr[1]] == 7 || this.data.mounthsarr[arr[1]] == 8 || this.data.mounthsarr[arr[1]] == 10 || this.data.mounthsarr[arr[1]] == 12) {
                this.setData({
                    daysarr: this.data.daysarr31
                })
            }
        }
        this.data.endtime = e.detail.value
        this.setData({
            endtime: e.detail.value,
            end: `${this.data.yearsarr[e.detail.value[0]]}/${this.data.mounthsarr[e.detail.value[1]]>10?this.data.mounthsarr[e.detail.value[1]]:'0'+this.data.mounthsarr[e.detail.value[1]]}/${this.data.daysarr[e.detail.value[2]]>10?this.data.daysarr[e.detail.value[2]]:'0'+this.data.daysarr[e.detail.value[2]]}`
        })
        console.log(this.data.end);
    },
    sure() {
        if (this.data.start == '起始时间') {
            wx.showToast({
                title: '请选择起始时间',
                icon: "none"
            })
        } else if (this.data.end == '结束时间') {
            wx.showToast({
                title: '请选择结束时间',
                icon: "none"
            })
        } else {
            if (this.data.type == 'okpaytime') {
                console.log(this.data.start);
                let startcode = new Date(this.data.start).getTime()
                let endcode = new Date(this.data.end).getTime()
                if (endcode >= startcode) {
                    this.setData({
                        beginPayTime: this.data.start,
                        endPayTime: this.data.end
                    })
                } else {
                    wx.showToast({
                        title: '起始时间不能大于结束时间请重新选择',
                        icon: "none"
                    })
                    return
                }
            } else if (this.data.type == 'oklogintime') {
                let startcode = new Date(this.data.start).getTime()
                let endcode = new Date(this.data.end).getTime()
                if (endcode >= startcode) {
                    this.setData({
                        beginLoginTime: this.data.start,
                        endLoginTime: this.data.end
                    })
                } else {
                    wx.showToast({
                        title: '起始时间不能大于结束时间请重新选择',
                        icon: "none"
                    })
                    return
                }
            } else if (this.data.type == 'okregistertime') {
                let startcode = new Date(this.data.start).getTime()
                let endcode = new Date(this.data.end).getTime()
                if (endcode >= startcode) {
                    this.setData({
                        beginRegisterTime: this.data.start,
                        endRegisterTime: this.data.end
                    })
                } else {
                    wx.showToast({
                        title: '起始时间不能大于结束时间请重新选择',
                        icon: "none"
                    })
                    return
                }
            } else if (this.data.type == 'nopaytime') {
                let startcode = new Date(this.data.start).getTime()
                let endcode = new Date(this.data.end).getTime()
                if (endcode >= startcode) {
                    this.setData({
                        beginPayTimeReverse: this.data.start,
                        endPayTimeReverse: this.data.end
                    })
                } else {
                    wx.showToast({
                        title: '起始时间不能大于结束时间请重新选择',
                        icon: "none"
                    })
                    return
                }
            } else if (this.data.type == 'nologintime') {
                let startcode = new Date(this.data.start).getTime()
                let endcode = new Date(this.data.end).getTime()
                if (endcode >= startcode) {
                    this.setData({
                        beginLoginTimeReverse: this.data.start,
                        endLoginTimeReverse: this.data.end
                    })
                } else {
                    wx.showToast({
                        title: '起始时间不能大于结束时间请重新选择',
                        icon: "none"
                    })
                    return
                }
            } else if (this.data.type == 'noregistertime') {
                let startcode = new Date(this.data.start).getTime()
                let endcode = new Date(this.data.end).getTime()
                if (endcode >= startcode) {
                    this.setData({
                        beginRegisterTimeReverse: this.data.start,
                        endRegisterTimeReverse: this.data.end
                    })
                } else {
                    wx.showToast({
                        title: '起始时间不能大于结束时间请重新选择',
                        icon: "none"
                    })
                    return
                }
            }
            this.setData({
                selectAll: false
            })
        }
        this.setData({
            selectAll: false
        })
    },
    selectall() {
        this.setData({
            selectAll: !this.data.selectAll,
        })
        if (this.data.selectAll && this.data.beginLoginTime != '' || this.data.beginPayTime != '' || this.data.beginRegisterTime != '' || this.data.serveCompanyIds.length != 0) {
            this.setData({
                showpop: true
            })
        } else {
            this.setData({
                showpop: false
            })
        }
    },
    // 监听是否全选
    observers: {
        'beginPayTimeReverse, endPayTimeReverse,beginLoginTimeReverse,endLoginTimeReverse,beginRegisterTimeReverse,endRegisterTimeReverse,serveCompanyIdsReverse': function (beginPayTimeReverse, endPayTimeReverse, beginLoginTimeReverse, endLoginTimeReverse, beginRegisterTimeReverse, endRegisterTimeReverse, serveCompanyIdsReverse) {
            if (beginPayTimeReverse != '', endPayTimeReverse != '', beginLoginTimeReverse != '', endLoginTimeReverse != '', beginRegisterTimeReverse != '', endRegisterTimeReverse != '', serveCompanyIdsReverse != [])
                this.setData({
                    selectAll: false
                })
        }
    },
    examine() {
        console.log('产看选择');
        wx.navigateTo({
            url: '../list-sorting/list-sorting?id=' + this.data.id,
        })
    },
    tomessagepay() {
        // let pageStack = getCurrentPages()
        // console.log(pageStack, '1111111111111111111')
        // console.log(app.getCurrentPages());
        let router = app.getCurrentPages()
        wx.setStorageSync('router', router)
        wx.navigateTo({
            url: '/packageMassmessage/pages/message-recharge/message-recharge',
        })
    },
    async sendmessage() {
        if (this.data.sendNumber != 0) {
            let res = await sendmessageapi({
                id: this.data.id,
                appId: "wx850e3a22db40acac"
            })
            if (res.code == 200) {
                wx.redirectTo({
                    url: '../../pages/send-success/send-success',
                })
            }
        } else {
            wx.showToast({
                title: '当前选定人数为0，请选择发送人员。',
                icon: "none"
            })
            this.setData({
                showorderpop: false,
                showtotle: false
            })
        }
    },
    popcancelorder() {
        this.setData({
            showorderpop: false
        })
    },
    async toissue() {
        if (this.data.showtotle) {
            this.setData({
                showorderpop: true
            })
            let res = await getmsessageresidueapi()
            // console.log(res.data.smsBalance);
            let res2 = await gethistorymessagedetailapi(this.data.id)
            console.log(res2);
            this.setData({
                msessageresidue: res.data.smsBalance,
                sendNumber: res2.data.sendNumber,
                sendafter: res.data.smsBalance - res2.data.sendNumber
            })
        } else {
            wx.showToast({
                title: '请先查询人数再发布',
                icon: 'none'
            })
        }
    },
    // 查看选择
    lookchoose() {
        console.log('产看选择');
        wx.navigateTo({
            url: '../list-sorting/list-sorting?id=' + this.data.id,
        })
    },
    async inquire() {
        let res = await queryandcreatethesender({
            massMessageId: this.data.id * 1,
            selectAll: this.data.selectAll === true ? 1 : 0,
            beginPayTime: this.data.beginPayTime,
            endPayTime: this.data.endPayTime,
            beginLoginTime: this.data.beginLoginTime,
            endLoginTime: this.data.endLoginTime,
            beginRegisterTime: this.data.beginRegisterTime,
            endRegisterTime: this.data.endRegisterTime,
            serveCompanyIds: this.data.serveCompanyIds,
            beginPayTimeReverse: this.data.beginPayTimeReverse,
            endPayTimeReverse: this.data.endPayTimeReverse,
            beginLoginTimeReverse: this.data.beginLoginTimeReverse,
            endLoginTimeReverse: this.data.endLoginTimeReverse,
            beginRegisterTimeReverse: this.data.beginRegisterTimeReverse,
            endRegisterTimeReverse: this.data.endRegisterTimeReverse,
            serveCompanyIdsReverse: this.data.serveCompanyIdsReverse,
        })
        let res2 = await gethistorymessagedetailapi(this.data.id)
        console.log(res2);
        if (res2.data.sendNumber != 0) {
            this.setData({
                sendNumber: res2.data.sendNumber,
                showtotle: true
            })
        } else {
            this.setData({
                sendNumber:0,
                showtotle:false
            })
            wx.showToast({
                title: '查询人数为0，请重新选择。',
                icon: 'none'
            })
        }
    },
    // 清除发送给谁
    async onSendingClean(){
        await confirm('确定清空吗?')
        await this.sureselectall()
        this.setData({
            showtotle:false,
            sendNumber:0
        })
    },
    // 清除不发送给谁
    async onNoSendingClean(){
        await confirm('确定清空吗?')
        this.setData({
            beginPayTimeReverse: "",
            endPayTimeReverse: "",
            beginLoginTimeReverse: "",
            endLoginTimeReverse: "",
            beginRegisterTimeReverse: "",
            endRegisterTimeReverse: "",
            serveCompanyIdsReverse: [],
            serveCompanyIdsReversename: [],
            // showtotle:false,
            // sendNumber:0
        })
    },
    sureselectall() {
        this.setData({
            showpop: false,
            beginPayTime: "",
            endPayTime: "",
            beginLoginTime: "",
            endLoginTime: "",
            beginRegisterTime: "",
            endRegisterTime: "",
            serveCompanyIds: [],
            serveCompanyIdsname: [],
        })
    },
    popcancel() {
        this.setData({
            showpop: false,
            selectAll: false
        })
    },
    dispatchingagency(e) {
        console.log(e);
        wx.navigateTo({
            url: '../dispatchingagency/dispatchingagency?sta=' + e.currentTarget.dataset.sta,
            events: {
                // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
                acceptUnitid: (data) => {
                    console.log(data)
                    if (data.data.sta === 'ok') {
                        this.setData({
                            serveCompanyIds: data.data.ok,
                            serveCompanyIdsname: data.data.okarr,
                        })
                    }
                    if (data.data.sta === 'no') {
                        this.setData({
                            serveCompanyIdsReverse: data.data.no,
                            serveCompanyIdsReversename: data.data.noarr
                        })
                    }
                },
            },
            success:(res)=> {
                // 通过eventChannel向被打开页面传送数据
                res.eventChannel.emit('acceptTransferIds', { data: e.currentTarget.dataset.sta == 'ok' ? this.data.serveCompanyIds : this.data.serveCompanyIdsReverse})
              }
        })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})